package com.sfx.concurrent.demo.concurrent.pattern.Guarded;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-31
 * Time: 13:13
 */

@Slf4j(topic = "c.Main")
public class Main {
    public static void main(String[] args) {
        GuardedObject guardedObject = new GuardedObject();
        //A线程等待B线程的结果
        new Thread(()->{
            List<String> list = (List<String>) guardedObject.get();
            log.debug("得到结果为");
            System.out.println(list);
        },"A").start();

        new Thread(()->{
            try {
                List<String> list = DownLoader.downLoad();
                guardedObject.complete(list);
            } catch (IOException e) {
                e.printStackTrace();
            }
        },"B").start();
    }
}